package com.infore.siteManagement.controller.ddic;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.siteManagement.entity.Project;
import com.infore.siteManagement.select.dto.QueryParamDto;
import com.infore.siteManagement.service.IndexService;
import com.infore.siteManagement.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author llf
 *因子管理接口
 *
 */

@Api(value = "指标管理接口", tags = {"指标管理接口" })
@RestController
@RequestMapping("/index")
public class IndexController {

	@Autowired
	private IndexService indexService;
	
	@ApiOperation(value = "查询指标通用接口")
	@ResponseBody
	@PostMapping(value = "/query")
	public ResultEntity queryProject(@RequestBody(required = false) QueryParamDto queryParamDto) {
		return indexService.queryProject(queryParamDto);
	}
	
	@ApiOperation(value = "删除指标通用接口")
	@ApiImplicitParams(@ApiImplicitParam(value = "因子id", name = "ids", paramType = "query",required = true,dataType = "String"))
	@DeleteMapping(value = "/delete")
	public ResultEntity deleteProject(String ids) {
		return indexService.deleteProject(ids);
	}
	
	@ApiOperation(value = "编辑/新增指标通用接口")
	@ResponseBody
	@ApiImplicitParams(@ApiImplicitParam(value = "类型id", name = "typeId", paramType = "query",required = true,dataType = "String"))
	@PostMapping(value = "/edit")
	public ResultEntity editProject(@RequestBody Project project,@RequestParam("typeId") String typeId) {
		return indexService.editProject(project,typeId);
	}
	
	@ApiOperation(value = "验证指标通用接口")
	@ResponseBody
	@PostMapping(value = "/validate")
	public ResultEntity validateProject(@RequestBody Project project) {
		return indexService.validateProject(project);
	}
	
	@ApiOperation(value = "下拉选因子信息（新增仪器参数）接口")
	@ResponseBody
	@PostMapping(value = "/projectInfo")
	public ResultEntity projectInfo() {
		return indexService.projectInfo();
	}
	
	@ApiOperation(value = "下拉选因子信息（新增仪器参数）接口")
	@ResponseBody
	@GetMapping(value="/getDownLine")
	public ResultEntity getDownLine(HttpServletRequest request) {
		return indexService.getDownLine(request);
	}
	
	@ApiOperation(value = "因子二级树")
	@ResponseBody
	@GetMapping(value="/projectTree")
	public ResultEntity projectTree() {
		return indexService.projectTree();
	}
	
	@ApiOperation(value = "根据因子名查询因子")
	@ResponseBody
	@GetMapping(value="/projectByName")
	public ResultEntity projectByName(String name) {
		return indexService.projectByName(name);
	}
}
